/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commands;

import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import servidorped.User;

/**
 *
 * @author Micosil
 */
public class admingetlogs implements Command {

    @Override
    public boolean execute(String[] stringlist, User user) {
        BufferedReader readLog = null;
        try {
            readLog = new BufferedReader(new FileReader(new File("./serverlog0.txt")));
        } catch (FileNotFoundException ex) {
            Logger.getLogger(admingetlogs.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
        String oneLine;
        try {
            while ((oneLine = readLog.readLine()) != null) {
                user.getUserSender().setToSend(oneLine);
            }
        } catch (IOException ex) {
            Logger.getLogger(admingetlogs.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        } finally {
            try {
                readLog.close();
            } catch (IOException ex2) {
                Logger.getLogger(admingetlogs.class.getName()).log(Level.SEVERE, null, ex2);
            }
        }
        try {
            readLog = new BufferedReader(new FileReader(new File("./serverlog1.txt")));
        } catch (FileNotFoundException ex) {
            Logger.getLogger(admingetlogs.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while ((oneLine = readLog.readLine()) != null) {
                user.getUserSender().setToSend(oneLine);
            }
        } catch (IOException ex1) {

            Logger.getLogger(admingetlogs.class.getName()).log(Level.SEVERE, null, ex1);
            return false;
        } finally {
            try {
                readLog.close();
            } catch (IOException ex2) {
                Logger.getLogger(admingetlogs.class.getName()).log(Level.SEVERE, null, ex2);
            }
        }
        Logger.getGlobal().log(Level.INFO, "Admin {0} viewed the logs." , user.getUserName() );
        return true;
    }
}
